package com.power.ex.handle;

import com.power.constant.BusinessEnum;
import com.power.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description 全局异常处理类
 * @Author dingchunlin
 * @Date 2024/07/11 22:20
 * @Version 1.0.0
 */
@RestControllerAdvice
@Slf4j
public class GloableExceptionHandle {


    @ExceptionHandler(BussinessException.class)
    public Result<String> bussinessException(BussinessException e) {
        log.error(e.getMessage());
        return Result.fail(BusinessEnum.OPERATION_FAIL.getCode(), e.getMessage());
    }

    /**
     * 处理权限异常
     * @param e 权限异常
     * @return Result
     */
    @ExceptionHandler(AccessDeniedException.class)
    public Result<String> accessDeniedExceptionHandler(AccessDeniedException e) {
        log.error(e.getMessage());
        throw e;
    }


}
